package com.zzyl.controller;

import com.github.pagehelper.Page;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingObjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description NursingProjectController
 * @Author lizhiwen
 * @Date 2024-09-06
 */

@RestController
@RequestMapping("/nursing_project")
public class NursingProjectController  extends BaseController {

    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage( @ApiParam(value = "护理项目名称")
                                                                 @RequestParam(value = "name", required = false) String name,
                                                             @ApiParam(value = "状态：0-禁用，1-启用")
                                                                 @RequestParam(value = "status", required = false) Integer status,
                                                             @ApiParam(value = "当前页码")
                                                                 @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                             @ApiParam(value = "每页显示数量")
                                                                 @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize){

        PageResponse<NursingProjectVo> page = nursingProjectService.getByPage(name, status, pageNum, pageSize);

        return success(page);
    }

    @PostMapping
    public ResponseResult add(@RequestBody NursingObjectDto nursingObjectDto){
        nursingProjectService.add(nursingObjectDto);

        return success();
    }

    @GetMapping("/{id}")
    public ResponseResult<NursingProjectVo> getById(@PathVariable Long id){
        NursingProjectVo nursingProjectVo = nursingProjectService.getById(id);

        return success(nursingProjectVo);

    }

    @PutMapping
    public ResponseResult update(@RequestBody NursingObjectDto nursingObjectDto){
        nursingProjectService.update(nursingObjectDto);

        return success();
    }

    @PutMapping("/{id}/status/{status}")
    public ResponseResult setStatus(@PathVariable Long id, @PathVariable Integer status){
        nursingProjectService.setStatus(id, status);

        return success();
    }

    @GetMapping("/all")
    public ResponseResult<List<NursingProjectVo>> findAll(){
        List<NursingProjectVo> list = nursingProjectService.findAll();

        return success(list);
    }

}
